package com.ngmaster.socket.message;

import com.ngmaster.socket.ProtocolMessage;
import io.swagger.annotations.ApiModelProperty;

import java.util.Arrays;

/**
 * 主动读取设备卡的ICCID
 * 接收应答一致:
 * 服务器可以主动请求，设备也可以主动上传
 */
public class ReadIccidFromDeviceMessage extends ProtocolMessage {

    /** 充值的数字 */
    private byte[] iccidBytes = new byte[icCidLength];

    /** 转换过来的iccid */
    @ApiModelProperty(notes = "设备的ICCID，读取的时候，可以填写20个0", example = "00000000000000000000")
    private String iccid;

    public byte[] getIccidBytes() {
        return iccidBytes;
    }

    public void setIccidBytes(byte[] iccidBytes) {
        this.iccidBytes = iccidBytes;
    }

    public String getIccid() {
        return iccid;
    }

    public void setIccid(String iccid) {
        this.iccid = iccid;
    }

    @Override
    public void onSerial() {
        this.byteArray.writeBytes(this.iccidBytes);
    }

    @Override
    public void onDeserialize() {
        this.byteArray.readBytes(this.iccidBytes, 0, this.iccidBytes.length);
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("ReadIccidFromDeviceMessage{");
        sb.append("iccidBytes=").append(Arrays.toString(iccidBytes));
        sb.append(", iccid='").append(iccid).append('\'');
        sb.append(", imeiBytes=").append(Arrays.toString(imeiBytes));
        sb.append(", imei='").append(imei).append('\'');
        sb.append(", cmd=").append(cmd);
        sb.append(", dataLength=").append(dataLength);
        sb.append(", crc=").append(crc);
        sb.append(", crcHex='").append(crcHex).append('\'');
        sb.append(", byteArray=").append(byteArray);
        sb.append('}');
        return sb.toString();
    }
}
